<template>
  <div class="total-container">
    <div v-if="!!topData" class="top-container">
      <div class="item-box" v-for="item in topData" :key="item.name">
        <div class="title">{{ item.name }}</div>
        <div class="value">
          <div class="num">
            <countTo :startVal="0" :endVal="item.num" :duration="1200" separator=""></countTo>
          </div>
          <div class="unit">{{ item.unit }}</div>
        </div>
      </div>
    </div>
    <div class="bottom-container">
      <div v-if="!!chartData.data.length" class="left-box">
        <pieChart :chart-data="chartData"></pieChart>
      </div>
      <div v-if="!!legend" class="right-box">
        <div class="legend-item" v-for="item in legend" :key="item.name">
          <div class="title">
            <div class="bar" :style="{ backgroundColor: item.barColor }"></div>
            <div class="name">{{ item.name }}</div>
          </div>
          <div class="value">
            <div class="left-value">
              <div class="num">{{ item.num1 }}</div>
              <div class="unit">{{ item.unit1 }}</div>
            </div>
            <div class="center-value">
              <div class="num">{{ item.num2 }}</div>
              <div class="unit">{{ item.unit2 }}</div>
            </div>
            <div class="right-value">
              <div class="rate">
                <span class="num">{{ item.num3 }}</span>
                <span class="unit">{{ item.unit3 }}</span>
              </div>
              <img class="arrow" src="../../img/right-row1-icon3.png" alt="" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import pieChart from '../charts/pieChart.vue'
import countTo from 'vue-count-to'
import { jjfz } from '@/api/dongyingData'
export default {
  data() {
    return {
      topData: [
        {
          name: 'GDP',
          num: 0,
          unit: '亿元'
        },
        {
          name: '人均GDP',
          num: 0,
          unit: '元'
        },
        {
          name: '进出口总额',
          num: 0,
          unit: '亿元'
        }
      ],
      chartData: {
        data: [],
        unit: '亿元',
        colors: ['#90D7F5', '#3FED8B', '#F5BA5E']
      },
      legend: null,
      barColor: ['#90D7F5', '#3FED8B', '#F5BA5E']
    }
  },
  components: {
    pieChart,
    countTo
  },
  mounted() {
    this.getData()
  },
  methods: {
    async getData() {
      const [res1, res2] = await Promise.all([jjfz.gk(), jjfz.sc()])
      this.topData[0].num = res1.result[0].gdp
      this.topData[1].num = res1.result[0].rjgdp
      this.topData[2].num = res1.result[0].jcke
      this.chartData.data = res2.result.map((item) => {
        return {
          name: item.sc,
          value: item.gdp
        }
      })
      this.legend = res2.result.map((item, index) => {
        return {
          name: item.sc,
          num1: item.zb,
          unit1: '%',
          num2: item.gdp,
          unit2: '亿元',
          num3: item.tb,
          unit3: '%',
          barColor: this.barColor[index]
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.total-container {
  .top-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    .item-box {
      width: 132px;
      height: 53px;
      background: rgba(43, 101, 156, 0.3);
      border-radius: 5px 5px 5px 5px;
      border: 1px solid #2b659c;
      padding-top: 5px;
      .title {
        font-family: MicrosoftYaHeiUI;
        font-size: 16px;
        color: #ffffff;
        line-height: 16px;
        text-align: center;
        font-style: normal;
        text-transform: none;
      }
      .value {
        display: flex;
        justify-content: center;
        align-items: baseline;
        margin-top: 5px;
        background: url('../../img/left-row3-icon1.png') no-repeat center center;
        background-size: 127px 23px;
      }
      .num {
        font-family: MicrosoftYaHeiUI, MicrosoftYaHeiUI;
        font-weight: bold;
        font-size: 20px;
        color: #16fdf5;
        line-height: 20px;
        text-align: center;
        font-style: normal;
        text-transform: none;
        background: radial-gradient(
          0deg,
          #ffffff 51%,
          #ffe5b9 54%,
          #ffc35b 100%
        );
      }
      .unit {
        font-family: MicrosoftYaHeiUI;
        font-size: 14px;
        color: #ffffff;
        line-height: 14px;
        text-align: center;
        font-style: normal;
        text-transform: none;
        margin-left: 3px;
      }
    }
  }
  .bottom-container {
    height: 150px;
    width: 100%;
    margin-top: 30px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    .left-box {
      height: 100%;
      width: 30%;
      background: url('../../img/right-row1-icon2.png') no-repeat center center;
      background-size: 32px 32px;
      position: relative;
    }
    .left-box::before {
      content: '';
      position: absolute;
      top: 13px;
      left: 0;
      height: 125px;
      width: 125px;
      background: url('../../img/right-row1-icon1.png') no-repeat center center;
      background-size: 100% 100%;
      animation: rotate 5s linear infinite;
    }
    @keyframes rotate {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(360deg);
      }
    }
    .right-box {
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      .legend-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .title {
        display: flex;
        justify-content: start;
        align-items: center;
        .name {
          width: 28px;
          font-family: MicrosoftYaHeiUI;
          font-size: 14px;
          color: #ffffff;
          line-height: 14px;
          text-align: left;
          font-style: normal;
          text-transform: none;
          margin-left: 3px;
        }
        .bar {
          width: 4px;
          height: 32px;
          border-radius: 2px 2px 2px 2px;
        }
      }
      .value {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 212px;
        height: 41px;
        background: rgba(29, 66, 118, 0.53);
        border-radius: 6px 6px 6px 6px;
        margin-left: 20px;
        .left-value,
        .center-value {
          text-align: center;
          .num {
            font-family: MicrosoftYaHeiUI, MicrosoftYaHeiUI;
            font-weight: bold;
            font-size: 18px;
            color: #ffffff;
            line-height: 18px;
            font-style: normal;
            text-transform: none;
          }
          .unit {
            font-family: MicrosoftYaHeiUI, MicrosoftYaHeiUI;
            font-weight: bold;
            font-size: 14px;
            color: #ffffff;
            line-height: 14px;
            font-style: normal;
            text-transform: none;
            margin-top: 1px;
          }
        }
        .right-value {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          .rate {
            .num,
            .unit {
              font-family: MicrosoftYaHeiUI, MicrosoftYaHeiUI;
              font-weight: bold;
              font-size: 18px;
              color: #ff3e3e;
              line-height: 18px;
              text-align: center;
              font-style: normal;
              text-transform: none;
            }
            .arrow {
              width: 8px;
              height: 12px;
            }
          }
        }
      }
    }
  }
}
</style>
